package com.thinkgem.jeesite.modules.sys.Jpush.examples;

import cn.jiguang.common.ClientConfig;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import com.thinkgem.jeesite.modules.sys.Jpush.JPushClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class ClientExample {
	protected static final Logger LOG = LoggerFactory.getLogger(ClientExample.class);

	private static final String appKey = "1c607d0540d5ee5c6fd9e948";
	private static final String masterSecret = "243078ec11672b379505cdba";

	public static void main(String[] args){
//		testDefaultClient();
//		testCustomClient();
//		testCustomPushClient();
		try {
			testsendAndroidMessageWithRegistrationID();
		}catch (Exception e){

		}
	}

	public static void testDefaultClient() {
		JPushClient client = new JPushClient(masterSecret, appKey);

	//	JPushClient client1 = new JPushClient(masterSecret, appKey, null, ClientConfig.getInstance());
	}

	public static void testCustomClient() {
		ClientConfig config = ClientConfig.getInstance();
		config.setMaxRetryTimes(5);
		config.setConnectionTimeout(10 * 1000);	// 10 seconds
		config.setSSLVersion("TLSv1.1");		// JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2

		JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
	}

	public static void testCustomPushClient() {
		ClientConfig config = ClientConfig.getInstance();

		config.setApnsProduction(false); 	// development env
		config.setTimeToLive(60 * 60 * 24); // one day

	//	config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day

		JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); 	// JPush client

	//	PushClient pushClient = new PushClient(masterSecret, appKey, null, config); 	// push client only

	}
	public static void testsendAndroidMessageWithRegistrationID() throws APIConnectionException, APIRequestException {
		ClientConfig config = ClientConfig.getInstance();

		config.setApnsProduction(false); 	// development env
		config.setTimeToLive(60 * 60 * 24); // one day

	//	config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day
		String title = "麻雀加急-";
		String alert = "您有一份新的订单等待派送!";
		Map<String, String> extras = new HashMap<String, String>();
		String [] registrationID = {"1104a89792a77205509","100d85590949ad35b10"};
		JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); 	// JPush client
		jPushClient.sendAndroidNotificationWithRegistrationID(title,alert,extras,registrationID);
	}
}


